package com.qjj.studydainty.adapter;


import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.qjj.studydainty.fragment.WebViewFragment;

import java.util.List;

public class WebPageAdapter extends FragmentPagerAdapter {

    private List<WebViewFragment> webViewFragmentList;
    private int deletePosition = -1;

    public WebPageAdapter(FragmentManager fm, List<WebViewFragment> webViewFragmentList) {
        super(fm);
        this.webViewFragmentList = webViewFragmentList;
    }

    @Override
    public WebViewFragment getItem(int position) {
        return webViewFragmentList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return webViewFragmentList.get(position).hashCode();
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    @Override
    public int getCount() {
        return webViewFragmentList.size();
    }

    public int getDeletePosition() {
        return deletePosition;
    }

    public void setDeletePosition(int deletePosition) {
        this.deletePosition = deletePosition;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        if (deletePosition == position) {
            deletePosition = -1;
            super.destroyItem(container, position, object);
        }
    }
}
